package com.syaccp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syaccp.model.TOrder;
import com.syaccp.service.TOrderService;
import com.syaccp.mapper.TOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author DX
* @description 针对表【t_order(订单表)】的数据库操作Service实现
* @createDate 2023-07-25 09:12:24
*/
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService{

    @Autowired
    TOrderMapper tOrderMapper;


    @Override
    public List<TOrder> queryByStyleId(Integer clientId,Integer styleId) {
        LambdaQueryWrapper<TOrder> queryWrapper = Wrappers.lambdaQuery(TOrder.class);
        queryWrapper.eq(ObjectUtils.isNotEmpty(styleId),TOrder::getFgfl,styleId);
        if(clientId!=null){
            if(clientId==1){    //好评
                queryWrapper.between(TOrder::getCommentNum,8,10);
            }else if(clientId==2){      //中评
                queryWrapper.between(TOrder::getCommentNum,5,7);
            }else {                 //差评
                queryWrapper.between(TOrder::getCommentNum,0,4);
            }
        }
        return tOrderMapper.selectList(queryWrapper);
    }

    @Override
    public TOrder queryByOrderId(Integer orderId) {
        LambdaQueryWrapper<TOrder> queryWrapper =Wrappers.lambdaQuery(TOrder.class);
        queryWrapper.eq(ObjectUtils.isNotEmpty(orderId),TOrder ::getId,orderId);
        return tOrderMapper.selectOne(queryWrapper);
    }


}




